<?php
class Client_Model extends CI_Model{
	
	public $common_model;
	public $openId;

	function __construct(){
		parent::__construct();
		$this->load->model('common_model');
		$this->common_model = &get_instance()->common_model;
		
	}
	


	function add($client,$client_phone){
		
		// 事务开始
		$this->db->trans_start();
		$this->db->insert('j_client', $client);
		$id= $this->db->insert_id();
		
		$client_phone['accountId'] = $id;
		
		$client_phone['state']=1;
		$this->db->insert('j_clientPhone', $client_phone);
		
		// 事务结束
		$this->db->trans_complete();
	}
	
	
	
	function update($data){
		$this->db->update('j_client', $data);
	}
	
	function delete($id){
		$this->db->delete('j_client', array('id' => $id));
	}
	

	/**
	 * 使用方法：
	 *$this->load->model('client_model');
	 *$this->client_model->query_page(0,10);
	 *
	 *
	 */
	function query_page($uid,$offset,$num,$order='created desc'){
		$table   = "j_client";
		$str_sql  = "select * from {$table} where creator={$uid}  order by {$order} limit {$offset},{$num}";
		
		//if($condition)
		//{
		//$str_sql = "select * from {$table} where 1=1 and username like '%" . $condition . "%' order by {$order} limit {$offset},{$num}";
			//}
			return array(
					'total' => $this->db->count_all('j_client'),
					'res' => $this->db->query($str_sql)->result_array(),
			);
		
			
		
// 		$this->db->select();
	
		$query = $this->db->get('j_client');
		$query = $this->db->where($where);		
		$query = $this->db->order_by("created","DESC");
		$query = $this->db->limit($limt,$offset);
		$result = $query->result_array();
		return $result;
	
	}
	
	public function query_one($table,$where){
		$this->db->where($where);
		$this->db->select('*');
		$query=$this->db->get($table);
		$one=$query->row_array();
		return $one;
	}
	
	
/*--------------------------------- 分 割 线 ----------------------------------------------*/	

	

	
	
	
	


	

	
	
	





}